use proc_macro::TokenStream;

use quote::quote;
use syn::{Data, DeriveInput, Fields, parse_macro_input};

pub fn field_type(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    let struct_name = &input.ident;

    let fields_and_types = match input.data {
        Data::Struct(ref data) => match data.fields {
            Fields::Named(ref fields) => {
                let field_names_and_types = fields.named.iter().map(|field| {
                    let field_name = field.ident.as_ref().unwrap().to_string();
                    let field_type = stringify!("{:?}", field.ty);
                    quote!((#field_name.to_string(), #field_type))
                });
                quote! {
                        impl #struct_name {
                                  fn get_fields_and_types() -> Vec<(String, String)> {
                                        vec![#(#field_names_and_types),*]
                      
                            }
                        }
                }
            }
            _ => quote!(),
        },
        _ => quote!(),
    };

    fields_and_types.into()
}